using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Data/State/Player/PlayerHit", fileName = "PlayerHit")]
public class PlayerState_Hit : PlayerState
{
    //
    public override void Enter()
    {
        base.Enter();
        playerControl.SetVelocity(Vector2.zero);
    }
    
    //
    public override void Exit()
    {
        base.Exit();
        // 镜头震动
        EventCenter.Instance.EventTrigger(EventName.EVENT_CAMERA_CAMERASHAKE);
        // 受伤音效
        AudioManager.Instance.PlayAudioSourceSFX(AudioSFXPath.PLAYER_HIT, stateMachine.gameObject);
        playerStatusInformation.PlayerIsHit = false;
    }
    
    //
    public override void LogicUpdate()
    {
        base.LogicUpdate();
        if (isAnimationFinished)
        {
            // 状态
            if(playerStatusInformation.GetPlayerIsDeath)
                stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Death)]);
            // 动画播放完，如果不在地面直接进入掉落状态，否则进入空闲状态
            if(!playerDetection.GetIsGround)
                stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Fall)]);
            stateMachine.SwitchState(stateMachine.stateTable[typeof(PlayerState_Idle)]);
        }
    }
    
    //
    public override void PhysicalUpdate()
    {
        base.PhysicalUpdate();
        animator.SetFloat("Horizontal", playerInput.axesX);
    }
}
